import java.util.Scanner;

public class Day_7_24 {

    //奇数位于偶数之前
    //调整数组顺序使得奇数位于偶数之前。调整之后，不关心大小顺序
    public static void main(String[] args) {
        int[] arr = {1,2,4,5,7,8,9};
        int left = 0;
        int right = arr.length - 1;
        while(left < right){
            while((left < right) && arr[left] % 2 != 0 ){
                left++;
            }
            while((left < right) && arr[right] % 2 == 0){
                right--;
            }
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    //求n！的累加和
    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        int ret = 1;
        for (int i = 1; i <=n ; i++) {
            ret = 1;
            for (int j = 1; j <=i ; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);
    }

    //求 n!
    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 1;
        for (int i = 1; i <=n ; i++) {
            sum = sum * i;
        }
        System.out.println(sum);
    }


    //有一组数据，只有一个数字是出现一次，其他是两次，请找出这个数字
    public static void main5(String[] args) {
        int[] array = {1,2,3,2,1};
        int sum = array[0];
        for (int i = 1; i < array.length; i++) {
            sum = sum ^ array[i];
        }
        System.out.println(sum);
    }


    //打印一个整数的每一位
    public static void print1(int n) {
        if(n > 9){
            print1(n / 10);
        }
        System.out.print(n % 10+" ");
    }

    public static void main4(String[] args) {
        print1(11545);
    }

    //获取一个数二进制序列中所有的偶数位和奇数位， 分别输出二进制序列   0111
    public static void printOne(int n){
        for (int i = 30; i >= 0 ; i-=2) {
            System.out.print(((n >> i) & 1)+" "); // 偶数
        }
        System.out.println();
        for (int i = 31; i >=1 ; i-=2) {          // 奇数
            System.out.print(((n >> i) & 1)+" ");
        }
    }

    public static void main3(String[] args) {
        printOne(11);
    }


    public static void findNum(int n) {
        for (int i = 1; i <= n ; i++) {
            int tmp = i;
            int count = 0;  //数字的位数
            while(tmp != 0){
                count++;
                tmp /= 10;
            }
            //count里面已经知道了这个数据等于几
            tmp = i;
            int sum = 0;
            while(tmp != 0){
                sum += Math.pow(tmp % 10,count);
                tmp /= 10;
            }
            if(sum == i){
                System.out.println(i);
            }
        }

    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        findNum(n);
    }


    //写一个函数返回
    public static void main1(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        int a  = scanner.nextInt();
        while(a!=0){
            if(a % 2 == 1){
                count++;
            }
            a = a / 2;
        }
        System.out.println(count);
    }

    public static int numofOne(int n) {
        int count = 0;
        while(n != 0){
            if((n & 1) == 1){
                count++;
            }
            n = n >>>1;
        }
        return count;
    }

    public static int numofOne2(int n) {
        int count = 0;
        while (n != 0){
            count++;
            n = n & (n-1);
        }
        return count;
    }
}
